package ca.etsmtl.log660.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.hibernate.Session;

import ca.etsmtl.log660.configuration.SessionFactoryHelper;
import ca.etsmtl.log660.entity.model.Genresfilm;
import ca.etsmtl.log660.entity.model.Utilisateurs;

/**
 * Servlet implementation class FormulaireRecherche
 */
@WebServlet("/FormulaireRecherche")
public class FormulaireRechercheServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FormulaireRechercheServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		HttpSession session = request.getSession(true);
        PrintWriter out = response.getWriter();
        
        Session uneSession = SessionFactoryHelper.getSessionFactory().openSession();
    	
		uneSession.beginTransaction();
		List<Genresfilm> genresFilm = uneSession.createQuery("FROM Genresfilm").list();

		String checkbox = "<td>Genre:</td><td>";
		
		for(int i=0;i<genresFilm.size();i++){
			checkbox += "<INPUT TYPE=CHECKBOX name='genresFilm' value='"+genresFilm.get(i).getNom()+"'>"+genresFilm.get(i).getNom()+"<br />";
		}
		
		checkbox += "</td>";
		
		session.setAttribute("genreFilms", checkbox);
		request.getRequestDispatcher("pages/formulaireRecherche.jsp").forward(request, response);

		
		uneSession.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
